<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="../include/admincontent.jsp" %>
<div id="location">当前位置：系统信息管理 > 岗位管理</div>
<div id="sy_search" class=" f0f0f0" style="display: inline-block">
    <form id="advanceQueryParam">
        <div style="background-color: #f0f0f0">
            <div class="clearfix more_query_area">
                <div class="query_area_body clearfix">
                    <div class="record_item">
                        <div class="record_item">
                            <div class="label">岗位编码:</div>
                            <div class="content">
                                <input type="text" name="code"/>
                            </div>
                        </div>
                    </div>
                    <div class="record_item">
                        <div class="record_item">
                            <div class="label">岗位名称:</div>
                            <div class="content">
                                <input type="text" name="name"/>
                            </div>
                        </div>
                    </div>
                    <div class="record_item">
                        <div class="record_item">
                            <div class="label">所属部门:</div>
                            <div class="content">
                                <input type="text" name="deptname" id="deptname" class="select" onFocus="blur()"/>
                                <input type="hidden" name="deptcode" id="deptcode"/>
                            </div>
                        </div>
                    </div>

                    <div class="record_item">
                        <div class="toolbars">
                            <a id="searchbtn">
                                <em class="ico16 search_16"></em>
                                <span class="menu_span" title="查询">查询</span>
                            </a>
                            <a id="searchreset">
                                <em class="ico16 refresh_16"></em>
                                <span class="menu_span" title="重置">重置</span>
                            </a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>
<div id="Content" class="bg-content">
    <div class="toolbars" style="height:30px;white-space:nowrap;width:auto;margin-left: 20px;" totalwidth="314">
        <a id="job_add">
            <em class="ico16 add_new"></em>
            <span class="menu_span">添加</span>
        </a>
        <a id="job_edit">
            <em class="ico16 editor_16"></em>
            <span class="menu_span">编辑</span>
        </a>
        <a id="job_del">
            <em class="ico16 del_16"></em>
            <span class="menu_span">删除</span>
        </a>
    </div>
</div>

<div style="overflow:hidden;">
    <div id="div_table" style="bottom: 0px">
        <table class="layui-hide" id="table" lay-filter="departmentTable"></table>
    </div>
</div>

<script type="text/javascript">
    $(document).ready(function () {
        $('input#deptname.select').click(function () {
            openLayer('选择部门', '/SysAdmin/getdepts', '90%', '98%');
        });
        $("#searchreset").on('click', (e) => {
            document.getElementById("advanceQueryParam").reset();
            $("input[name='deptcode']").val("")
        });

    });
    layui.use('table', () => {
        let table = layui.table;
        table.render({
            id: 'table'
            , elem: '#table'
            , height: 'full'
            , url: '/SysAdmin/getJobsLayuiJson' //数据接口
            , title: '用户表'
            , page: true //开启分页
            , cols: [[ //表头
                {type: 'checkbox', fixed: 'left'}
                , {type: 'numbers', title: '序号', width: '10%', sort: true}
                , {field: 'code', title: '岗位编码', width: '20%', sort: true}
                , {field: 'name', title: '岗位名称', width: '30%'}
                , {field: 'deptname', title: '部门名称', width: '30%'}
                , {
                    field: 'type', title: '岗位类型', width: '10%'
                }
            ]]
            , done: (res, curr, count) => {
                tableresize(diff, false)
            }
        });
        reload = () => {
            table.reload('table');
        }
        document.tablereload = reload;
        $("#searchbtn").on('click', () => {
            table.reload('table', {
                    where: {
                        code: $("input[name='code']").val(),
                        name: $("input[name='name']").val(),
                        deptcode: $("input[name='deptcode']").val(),
                    }, page: {
                        curr: 1
                    }
                }
            )
        });
        //添加岗位
        $('#job_add').click(function () {
            openLayer('添加岗位', '/SysAdmin/jobAdd', '700px', '90%');
            reload();
        });

        //修改岗位
        $('#job_edit').click(function () {

                let url = "";
                let chosendata = layui.table.checkStatus('table').data;
                if (chosendata.length > 0 || chosendata.length > 1) {

                    url = '/SysAdmin/jobAdd?code=' + chosendata[0].code
                        + '&id=' + chosendata[0].id
                        + '&name=' + chosendata[0].name
                        + '&deptname=' + chosendata[0].deptname
                        + '&deptcode=' + chosendata[0].deptcode
                        + '&type=' + chosendata[0].type;
                    openLayer('编辑岗位', url, '700px', '90%');
                } else {
                    layer.msg('请选择一条信息', {icon: 7, time: 2000});
                }
            }
        );

        //删除岗位
        $('#job_del').click(function () {
            let chosendata = layui.table.checkStatus("table").data;
            if (chosendata.length === 0) {
                layer.msg('请选择要执行该操作的信息', {icon: 7, time: 2000});
            } else {
                chosendata = chosendata.map((d) => {
                    return {id: d.id}
                })
                $.ajax({
                    type: 'post',
                    dataType: "json",
                    url: '/SysAdmin/jobDel',
                    data: JSON.stringify(chosendata),
                    contentType: 'application/json;charset=utf-8',
                    error: function () {
                        layer.alert('服务器连接失败', {icon: 5, time: 5000});
                    },
                    success: function (msg) {
                        layer.msg(msg.msg, {icon: 1, time: 2000});
                        reload();
                    }
                });
            }
        });

        function tableresize(diff, resizeout = true) {
            let height3 = $("#div_table").height();
            let height4 = $(".layui-table-body.layui-table-main").height();
            let height5 = $(".layui-form.layui-border-box.layui-table-view").height();


            if (resizeout) {
                $("#div_table").height(height3 - diff);
            }
            $(".layui-table-body.layui-table-main").height(height4 - diff);
            $(".layui-form.layui-border-box.layui-table-view").height(height5 - diff);
        }

        let diff;

        let origin = {};
        $("#combineQuery").on('click', (e) => {

            let style = $("#advanceQueryParam")[0].style;
            if (style.display === 'block') {
                style.display = 'none';
                diff = -origin.diff;
            } else {
                style.display = 'block';
                if (!origin.diff) {
                    origin.diff = document.documentElement.scrollHeight - document.documentElement.clientHeight;
                }
                diff = origin.diff;
            }

            tableresize(diff);
        });
    });
</script>
</body>
</html>